﻿using AutoMapper;
using B.S.BasicData.Domain;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interfance;
using B.S.BasicData.Read.Apilication.Common.Delparment;
using B.S.BasicData.Read.DTOS;
using MediatR;

namespace B.S.BasicData.Read.Apilication.Handler.Delparment
{
    public class GetDelparmentNameHandler : IRequestHandler<GetDelparmentNameCommon, ApiResult<List<SetuserDTO>>>
    {
        private readonly IBaseRepository<UserModel> userRepo;
        private readonly IMapper mapper;

        public GetDelparmentNameHandler(IBaseRepository<UserModel> userRepo,IMapper mapper)
        {
            this.userRepo = userRepo;
            this.mapper = mapper;
        }
        public Task<ApiResult<List<SetuserDTO>>> Handle(GetDelparmentNameCommon request, CancellationToken cancellationToken)
        {
            ApiResult<List<SetuserDTO>> res=new ApiResult<List<SetuserDTO>>();

            var setname = userRepo.GetAll().Where(x=>x.DepartmentID==request.DepartmentID);

            var model=mapper.Map<List<SetuserDTO>>(setname);

            res.Data = model;
            res.Message = "查询用户成功";
            res.Code=ApiEnum.Success;
            return Task.FromResult(res);



        }
    }
}
